import { Inject, Injectable, Scope } from '@nestjs/common';
import { REQUEST } from '@nestjs/core';
import { Request } from 'express';
import {UserEntity} from "@/db/entitys/user.entity";

@Injectable({ scope: Scope.REQUEST })
export class ReqProvider {
  get user(): UserEntity | undefined {
    return this._req.user as (UserEntity | undefined)
  }
  get req(): Request {
    return this._req
  }

  get domain(): string {
    const req = this._req
    // return `${req.protocol}://${req.get('host')}${req.originalUrl}`
    return `${this._req.protocol || "http"}://${this._req.get("host")}`
  }

  constructor(@Inject(REQUEST) private readonly _req: Request) {}
}